< previous page page_620 next page >

Page 620
e10a6a0a59f035e870d90cca05b85fce.gif
Dim B24AC As Single
Dim t1 As Single
Dim t2 As Single

    ' Find the axis vector.
    Wx = Point2.Trans(1) - Point1.Trans(1)
    Wy = Point2.Trans(2) - Point1.Trans(2)
    Wz = Point2.Trans(3) - Point1.Trans(3)

    ' Find A and B for u = A * t + B.
    w_len_squared = Wx * Wx + Wy * Wy + Wz * Wz
    WdotV = Wx * Vx + Wy * Vy + Wz * Vz
    A = WdotV / w_len_squared

    x1 = Point1.Trans(1)
    y1 = Point1.Trans(2)
    z1 = Point1.Trans(3)
    B = (Wx * (px - x1) + _ 
         Wy * (py - y1) + _ 
         Wz * (pz - z1)) / w_len_squared 
     
    ' Solve for t.
    Cx = Vx - Wx * A
    Cy = Vy - Wy * A
    Cz = Vz - Wz * A
    dx = px - x1 - Wx * B
    dy = py - y1 - Wy * B
    dz = pz - z1 - Wz * B
    A1 = Cx * Cx + Cy * Cy + Cz * Cz
    b1 = 2 * (Cx * dx + Cy * dy + Cz * dz)
    C1 = dx * dx + dy * dy + dz * dz - Radius * Radius

    ' Solve the quadratic A1*t^2 + B1*t + C1 = 0.
    B24AC = b1 * b1 - 4 * A1 * C1
    If B24AC < 0 Then
        RayTraceable_FindT = -1
        Exit Function
    ElseIf B24AC = 0 Then 
        t1 = -b1 / 2 / A1 
    Else
        B24AC = Sqr(B24AC) 
        t1 = (-b1 + B24AC) / 2 / A1 
        t2 = (-b1 - B24AC) / 2 / A1 
        ' Use only positive t values.
        If t1 < 0.02 Then t1 = t2
        If t2 < 0.02 Then t2 = t1
        ' Use the smaller t value.
        If t1 > t2 Then t1 = t2
    End If
    
    ' If there is no positive t value, there's no
    ' intersection in this direction.

 
< previous page page_620 next page >